﻿using FE.Service.Contract;
using FE.Shared.Enum;
using Microsoft.Extensions.Configuration;
using System;
using System.IO;

namespace FE.Service
{
    public class ConfigurationService : IConfigurationService
    {
        private const string JsonFileName = "app.json";

        private IConfiguration Configuration { get; }

        public ConfigurationService(IConfiguration configuration)
        {
            Configuration = configuration;
        }

        //public string aa()
        //{
        //    var s = Configuration[key: "ConnectionStrings:Database"];
        //}

        public string LiteDbConnectionStr => Configuration[key: "LiteConnectionStrings:Database"];

        public string LocalJsonFilePath => GetLocalConfigByType(LocalConfigType.App);

        private string GetLocalConfigByType(LocalConfigType configType)
        {
            var root = Configuration[key: "LocalSettings:ExportRootPath"];

            switch (configType)
            {
                case LocalConfigType.App:
                    if (string.IsNullOrEmpty(root))
                    {
                        return Path.Combine(AppContext.BaseDirectory, JsonFileName);
                    }
                    else
                    {
                        return Path.Combine(root, JsonFileName);
                    }

                default:
                    return "";
            }
        }

        public void Init()
        {
        }

        //private string GetLocalConfig()
    }
}